package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.Discipline;
import com.ruoyi.system.mapper.DisciplineMapper;
import com.ruoyi.system.mapper.TeacherMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ScheduleMapper;
import com.ruoyi.system.domain.Schedule;
import com.ruoyi.system.service.IScheduleService;

import javax.annotation.Resource;

/**
 * 课程Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-18
 */
@Service
public class ScheduleServiceImpl implements IScheduleService 
{

    @Autowired
    private ScheduleMapper scheduleMapper;

    @Resource
    private DisciplineMapper disciplineMapper;

    @Resource
    private TeacherMapper teacherMapper;

    /**
     * 查询课程
     * 
     * @param scheduleId 课程主键
     * @return 课程
     */
    @Override
    public Schedule selectScheduleByScheduleId(Long scheduleId)
    {
        return scheduleMapper.selectScheduleByScheduleId(scheduleId);
    }

    /**
     * 查询某个班级下的课表
     * @param cid
     * @return
     */
    @Override
    public List<Schedule> selectScheduleByClassId(Integer cid) {
        List<Schedule> schedules = scheduleMapper.selectScheduleByClassId(cid);
        for (int i = 0; i < schedules.size(); i++) {
            Discipline discipline = disciplineMapper.selectDisciplineByDid(schedules.get(i).getDid());
            String teacherName = teacherMapper.selectTeacherByTid(discipline.getTid()).getTeacherName();
            schedules.get(i).setTeacherName(teacherName);
        }
        return schedules;
    }

    /**
     * 查询课程列表
     * 
     * @param schedule 课程
     * @return 课程
     */
    @Override
    public List<Schedule> selectScheduleList(Schedule schedule)
    {
        return scheduleMapper.selectScheduleList(schedule);
    }

    /**
     * 新增课程
     * 
     * @param schedule 课程
     * @return 结果
     */
    @Override
    public int insertSchedule(Schedule schedule)
    {
        schedule.setCreateTime(DateUtils.getNowDate());
        return scheduleMapper.insertSchedule(schedule);
    }

    /**
     * 修改课程
     * 
     * @param schedule 课程
     * @return 结果
     */
    @Override
    public int updateSchedule(Schedule schedule)
    {
        schedule.setUpdateTime(DateUtils.getNowDate());
        return scheduleMapper.updateSchedule(schedule);
    }

    /**
     * 批量删除课程
     * 
     * @param scheduleIds 需要删除的课程主键
     * @return 结果
     */
    @Override
    public int deleteScheduleByScheduleIds(Long[] scheduleIds)
    {
        return scheduleMapper.deleteScheduleByScheduleIds(scheduleIds);
    }

    /**
     * 删除课程信息
     * 
     * @param scheduleId 课程主键
     * @return 结果
     */
    @Override
    public int deleteScheduleByScheduleId(Long scheduleId)
    {
        return scheduleMapper.deleteScheduleByScheduleId(scheduleId);
    }
}
